//
//  FBMeUser.swift
//  Weibo_SwiftDemo
//
//  Created by gjh on 2020/12/14.
//

import Foundation

@objcMembers class FBMeUser {
    var name: String?
    var avatarName: String?
    var education: String?
    
    init(name: String, avatarName: String = "bayMax", education: String) {
        self.name = name
        self.avatarName = avatarName
        self.education = education
    }
    
    class func propertyList() -> [String] {
        var count: UInt32 = 0
        
        // 1.获取类的属性列表,返回属性列表的数组,可选项
        let listProperty = class_copyPropertyList(self, &count)
        
        // 2.遍历数组
//        for i in 0..<Int(count) {
//            let property = (listProperty?[i])!
//            let cName = property_getName(property)
//            let name = String(utf8String: cName)
//            print(name!)
//        }
        // 为了不使用强制解包操作  使用 guard let 最合适
        for i in 0..<Int(count) {
            guard let property = listProperty?[i],
                  let name = String(utf8String: property_getName(property))
            else { continue }
            print(name)
        }
        free(listProperty)
        return []
    }
}
